<template>

    <el-row class="home" :gutter="20">
      <el-col :span="8" style="margin-top: 20px">
          
        <el-card shadow="hover">
          <div class="user">
            <img :src="getImageUrl('user')"  class="user" />
            <div class="user-info">
              <p>Admin</p>
              <p>超级管理员</p>
            </div>
          </div>
          <div class="login-info">
            <p>上次登录时间:<span>2022-7-11</span></p>
            <p>上次登录的地点:<span>北京</span></p>
          </div>
        </el-card>
          
        <el-card shadow="hover" class="table" >
            
          <el-table :data="tableData">
            <el-table-column
              v-for="(val, key) in tableLabel"
              :key="key"
              :prop="key"
              :label="val"
            >
            </el-table-column>
          </el-table>
            
        </el-card>
  
      </el-col>
      <el-col :span="16" style="margin-top: 20px">
    
            <div class="num">
            <el-card
                :body-style="{ display: 'flex', padding: 0 }"
                v-for="item in countData"
                :key="item.name"
            >
                <component
                class="icons"
                :is="item.icon"
                :style="{ background: item.color }"
                ></component>
                
                <div class="detail">
                <p class="num">￥{{ item.value }}</p>
                <p class="txt">{{ item.name }}</p>
                </div>
            </el-card>
            </div>
        
        </el-col>
        
    </el-row>
  </template>
  <script setup>
  import {ref} from 'vue'
  const tableData=ref([])
  import {onMounted,getCurrentInstance} from 'vue'
    //这个proxy相当于组件对象        //getCurrentInstance它的作用是获取当前组件的实例对象。
    const { proxy } = getCurrentInstance()
    const getTableData=async ()=>{
    const data = await proxy.$api.getTableData()
        tableData.value=data.tableData
    }
    
  const getImageUrl = (user) => {
        return new URL(`../assets/images/${user}.png`, import.meta.url).href;
  }

  const tableLabel = ref({
      name: "课程",
      todayBuy: "今日购买",
      monthBuy: "本月购买",
      totalBuy: "总购买",
  })
  const countData = ref([])
  const getCountData=async ()=>{
    const data = await proxy.$api.getCountData()
    countData.value=data
    }
onMounted(()=>{
    getTableData()
    getCountData()
})
  
  
  </script>

<style lang="less" scoped >

.home {
    height: 100%;
    overflow: hidden;
    .user {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #ccc;
    margin-bottom: 20px;
    img {
      width: 150px;
      height: 150px;
      border-radius: 50%;
      margin-right: 40px;
    }
  }
  .login-info {
    p {
      line-height: 30px;
      font-size: 14px;
      color: #999;
      span {
        color: #666;
        margin-left: 60px;
      }
    }
  }
  .table{
    margin-top: 20px;
  }
  .num {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .el-card {
      width: 32%;
      margin-bottom: 20px;
    }
    .icons {
      width: 80px;
      height: 80px;
      font-size: 30px;
      text-align: center;
      line-height: 80px;
      color: #fff;
    }
    .detail {
      margin-left: 15px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .num {
        font-size: 30px;
        margin-bottom: 10px;
      }
      .txt {
        font-size: 14px;
        text-align: center;
        color: #999;
      }
    }
  }
  .top-echart{
    height: 280px
  }
  .graph {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    .el-card {
      width: 48%;
      height: 260px;
    }
  }
}

</style>